USE [Hmis_Billing]
GO


Select T.GeoName, A.* 
From [HMIS.OTHERS.DB].[Hmis_CommonData].[dbo].[CD_Area] A
Join [HMIS.OTHERS.DB].[Hmis_CommonData].[dbo].[CD_AreaTypes] T On A.TypeID = T.ID
Where A.GeoName Like N'%ნინო%წმინდ%' --And A.ID = '5F269529-2A24-483D-AAC2-06E735DF60E9'
	And A.TypeID In ('91BBFB30-9F12-46CB-AE8A-4236D500FCA7', 'E290500D-46BF-4F28-B2B3-99D6706EF661', '7E989FFC-DB07-46DD-91AD-A0AFF06A2C55')


Declare @ParentId UniqueIdentifier, @ProviderStatusID UniqueIdentifier, @OrganizationTypeID UniqueIdentifier, @ProviderTypeID UniqueIdentifier, @GeoName NVarChar(400), @Tax NVarChar(20), @LegalFormID UniqueIdentifier, 
		@NumberInMunicipality Numeric(2, 0), @AreaID UniqueIdentifier, @Address As NVarChar(400), @DateCreated DateTime, @BranchId UniqueIdentifier


Set @ParentId = NewId()
Set @BranchId = NewId()
Set @ProviderStatusID = 'CA6FB1CF-E0E9-4F4E-9209-409EB793BDE2' --აქტიური
Set @OrganizationTypeID = 'C33990F5-7F0B-406C-8A34-7311BAE992A5' --სერვისის მომწოდებელი
Set @ProviderTypeID = Null
Set @GeoName = N''
Set @Tax = N''
Set @LegalFormID = ''
Set @NumberInMunicipality = 
Set @AreaID = ''
Set @Address = N''
Set @DateCreated = GetDate()



Select 'ProviderIDs' As [ProviderIDs], * From dbo.BL_Providers Where ID In (@ParentId, @BranchId)
Select '@ProviderStatusID' As [ProviderStatusID], * From dbo.BL_ProviderStatuses Where ID = @ProviderStatusID
Select '@OrganizationTypeID' As [OrganizationTypeID], * From dbo.BL_OrganizationTypes Where ID = @OrganizationTypeID
Select '@LegalFormID' As [LegalFormID], * From dbo.BL_LegalForms Where ID = @LegalFormID
Select '@ProviderTypeID' As [ProviderTypeID], * From dbo.BL_ProvidersTypes Where ID = @ProviderTypeID


Select T.GeoName, A.* 
From [HMIS.OTHERS.DB].[Hmis_CommonData].[dbo].[CD_Area] A
Join [HMIS.OTHERS.DB].[Hmis_CommonData].[dbo].[CD_AreaTypes] T On A.TypeID = T.ID
Where A.ID = @AreaID


Begin Tran

--select newId()

INSERT INTO [dbo].[BL_Providers]
           ([ID]
           ,[OLD_ID]
           ,[Level]
           ,[OrganizationTypeID]
           ,[ParentID]
           ,[ProviderTypeID]
           ,[ProviderStatusID]
           ,[GeoName]
           ,[EngName]
           ,[IsMedical]
           ,[TAX]
           ,[LegalFormID]
           ,[NumberInMunicipality]
           ,[AreaID]
           ,[Address]
           ,[Email]
           ,[Tel]
		   ,IsParent
           ,[DateCreated])
     VALUES
           (
			@ParentId
           ,-1 --OLD_ID
           ,0 --Level
           ,@OrganizationTypeID
           ,Null --ParentID
           ,@ProviderTypeID
           ,@ProviderStatusID
           ,@GeoName
           ,'' --EngName
           ,1 --IsMedical
           ,@Tax
           ,@LegalFormID
           ,@NumberInMunicipality
           ,@AreaID
           ,@Address
           ,Null --Email
           ,Null --Tel
		   ,0
           ,@DateCreated
		)


INSERT INTO [dbo].[BL_Providers]
           ([ID]
           ,[OLD_ID]
           ,[Level]
           ,[OrganizationTypeID]
           ,[ParentID]
           ,[ProviderTypeID]
           ,[ProviderStatusID]
           ,[GeoName]
           ,[EngName]
           ,[IsMedical]
           ,[TAX]
           ,[LegalFormID]
           ,[NumberInMunicipality]
           ,[AreaID]
           ,[Address]
           ,[Email]
           ,[Tel]
		   ,IsParent
           ,[DateCreated])
     VALUES
           (
			@BranchId
           ,-1 --OLD_ID
           ,0 --Level
           ,@OrganizationTypeID
           ,@ParentId
           ,Null --ProviderTypeID
           ,@ProviderStatusID
           ,@GeoName
           ,'' --EngName
           ,1 --IsMedical
           ,@TAX
           ,@LegalFormID
           ,@NumberInMunicipality
           ,@AreaID
           ,@Address
           ,Null --Email
           ,Null --Tel
		   ,0
           ,@DateCreated
		)


--Commit Tran



